package com.oepm.common.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration//就如@component
@EnableSwagger2//开启swagger2
public class SwaggerConfig {
    //配置swagger的Docket Bean实例
    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("秦时陈胜");
    }
    @Bean
    public Docket docket(Environment environment){
        //获取项目环境,因为正式项目时不需要swawgger
        Profiles profiles = Profiles.of("dev");
        boolean flag =environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //是否请用swagger，false则不能在浏览器访问
                .enable(flag)
                .groupName("Panda熊")
                .select()
                //配置要扫描接口的方式
                //basePackage指定要扫描的包，一般用这个跟
                // .withClassAnnotation()扫描类上对应的注解，通过反射方式
                //.apis(RequestHandlerSelectors.basePackage("com.oepm.apply.controller"))
                .apis(RequestHandlerSelectors.basePackage("com.oepm.web.controller"))
                //paths过滤掉不扫描的
//                .paths(PathSelectors.any())
                .build();
    }
    //配置swagger的信息=apiinfo
    private ApiInfo apiInfo(){
        Contact DEFAULT_CONTACT = new Contact("", "", "");
        return new ApiInfo("OEPM——课外开放实验项目API",
                "冲冲冲",
                "1.0",
                "urn:tos",
                DEFAULT_CONTACT,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());

    }
}
